<template>
    <el-form style="width: 60%" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="id" prop="id">
            <el-input v-model="ruleForm.id" readOnly></el-input>
        </el-form-item>
        <el-form-item label="部门名称" prop="name">
            <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
            <el-button @click="back()">返回</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    export default {
        data() {
            return {
                ruleForm: {
                    name: '',
                    id: ''
                },
                rules: {
                    name: [
                        { required: true, message: '部门名称不能为空', trigger: 'blur' },],
                }
            };
        },
        methods: {
            back(){
                this.$router.push("/queryCollege")
            },
            submitForm(formName) {
                const _this=this
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        axios.post('http://localhost:8181/college/saveCollege',this.ruleForm).then(function(resp) {
                            console.log(resp)
                            if (resp.data=='success'){
                                _this.$alert('部门：'+_this.ruleForm.name+'修改成功', '消息', {
                                    confirmButtonText: '确定',
                                    callback: action => {
                                        _this.$router.push("/queryCollege")
                                    }
                                });
                            }
                        })
                    } else {
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        },
        created(){
            const _this=this
            axios.get('http://localhost:8181/college/findById/'+this.$route.query.id).then(function (resp) {
                _this.ruleForm=resp.data

            })
        },
    }
</script>